<?php
namespace Controllers;
class CommonController {
    public function render ($tpl, $data = []) {
        $filePath = './Views/' . $tpl . '.php';
        if (!file_exists($filePath)) {
            echo 'The view ' . $tpl . ' is not exists'; exit;
        }
        extract($data);// $items
        include_once $filePath;
    }

    public function jsonResponse($code = 1, $msg = '', $data = []) {
        $array = compact('code', 'msg', 'data');
        // ['code' => 1, 'msg' => '大幅度', 'data' => []]
        return json_encode($array);
    }
}